//费用与收益列表
function subGridRowExpanded(subgrid_id, row_id) {
	var rowData = $prdFeeYieldList.jqGrid('getRowData', row_id);
	var subgrid_table_id = subgrid_id+"_t";
	var feeName = $.trim($("#q-feeName").val());
    var expectPayDateBegin = $("#q-expectPayDate").getDateRangeValue()[0];
    var expectPayDateEnd = $("#q-expectPayDate").getDateRangeValue()[1];
    var bnsDateBegin = $("#q-bnsDate").getDateRangeValue()[0];
    var bnsDateEnd = $("#q-bnsDate").getDateRangeValue()[1];
    var isPay = $("#q-isPay").val();
	var feeType = $('#q-feeType').val();
	$("#subGridTBId").val(subgrid_table_id);
	var pager_id = "p_"+subgrid_table_id;
	$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
 		
	jQuery("#"+subgrid_table_id).jqGrid({
		//caption: '费用与收益列表',
		url:   PATH_PREFIX+ 'feeYieldListPage.do',
		datatype: "json",
		colNames: ['ID',"","",'名称','类型','预计支付日','预计支付金额','实际支付日','实际支付金额',"","","","操作"],    
		colModel: [
			      {name:'mk',index:'mk',hidden:true,key:true},
				  {name:'feeId',index:'feeId',hidden:true,sortable:false},
				  {name:'cashFlowsDate',index:'cashFlowsDate',hidden:true,sortable:false},
				  {name:'feeName',index:'feeName',align:'left',width: 20,sortable:false},
				  {name:'oldFeeName',index:'oldFeeName',align:'left',width: 20,sortable:false},
				  {name:'expectPayDate',index:'expectPayDate',align:'left',width: 20,sortable:false},
				  {name:'expectPayAmount',index:'expectPayAmount',align:'left',width: 20,sortable:false},
				  {name:'bnsDate',index:'bnsDate',align:'left',width: 20,sortable:false},
				  {name:'bnsAmt',index:'bnsAmt',align:'left',width: 20,sortable:false},
				  {name:'type',index:'type',hidden:true,sortable:false},
				  {name:'subPrdCode',index:'subPrdCode',hidden:true,sortable:false},
				  {name:'subFundsName',index:'subFundsName',hidden:true,sortable:false},
		          {name:'option', index:'option', width: 20, resizable: true, sortable: false }
				  ],
        rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        postData:{
		 	'sp[subPrdCode]': rowData.subPrdCode,
		 	'sp[feeName]':feeName,
	    	'sp[expectPayDateBegin]':expectPayDateBegin,
	    	'sp[expectPayDateEnd]':expectPayDateEnd,
	    	'sp[bnsDateBegin]':bnsDateBegin,
	    	'sp[bnsDateEnd]':bnsDateEnd,
		 	'sp[feeType]': feeType,
		 	'sp[isPay]':isPay
		},
        rownumWidth: 50,
        prmNames: {
        	        search: "search", 
        	        page: "pageNo",
        	        rows: "limit" 
        	       },
        height: 'auto',
        width: false,
        autowidth:true,
        shrinkToFit:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },
        multiselect: false,
        pager: "#" + pager_id, 	
        viewrecords: true,
        hidegrid: false,	
		gridComplete: function(){
			var ids = jQuery("#"+subgrid_table_id).jqGrid('getDataIDs');
			for (var i = 0; i < ids.length; i++) {
                var id = ids[i];
                var rowData = jQuery("#"+subgrid_table_id).jqGrid('getRowData', id);
                var feeId = rowData.feeId;
                var cashFlowsDate = rowData.cashFlowsDate;
                var feeName = rowData.feeName;
                var oldFeeName = rowData.oldFeeName;
                var subFundsName = rowData.subFundsName;
                var type = rowData.type;
	            var updateBtn = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="修改" onclick="updateFeeOrYieldInfo(\''
	            +feeId+ '\',\''
	            +cashFlowsDate+ '\',\''
	            +feeName+ '\',\''
	            +oldFeeName+ '\',\''
	            +subFundsName+ '\',\''
				+type
				+'\');">修改</a>';
	            
	            var deleteBtn = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="删除" disabled>删除</a>';
	            deleteBtn = '<a href="javascript:void(0);" class="btn btn-link btn-jqgrid" title="删除" onclick="deleteFeeOrYieldInfo(\''
            	+feeId+ '\',\''
	            +cashFlowsDate+ '\',\''
				+type
            	+'\');">删除</a>';
	            
	            var params = {
						'updateDataInfo'    : 	'updateDataInfoTemp',
						'deleteDataInfo'    : 	'deleteDataInfoTemp'
					};
					
				var permissionButton = Permission_Button.configPermissionButton(params);
				
				permissionButton.updateDataInfo = Permission_Button.clickPermissionButton('updateDataInfoTemp','updateFeeOrYieldInfo(\''
			            +feeId+ '\',\''
			            +cashFlowsDate+ '\',\''
			            +feeName+ '\',\''
			            +oldFeeName+ '\',\''
			            +subFundsName+ '\',\''
						+type
						+'\');');
				
				permissionButton.deleteDataInfo = Permission_Button.clickPermissionButton('deleteDataInfoTemp','deleteFeeOrYieldInfo(\''
		            	+feeId+ '\',\''
			            +cashFlowsDate+ '\',\''
						+type
		            	+'\');');
				
	            jQuery("#"+subgrid_table_id).jqGrid('setRowData', ids[i], { option: Permission_Button.linkAllBtn(permissionButton)});
			}
		}
	});
	jQuery("#"+subgrid_table_id).navGrid('#'+pager_id,{edit:false,add:false,del:false,search:false});
}

function updateFeeOrYieldInfo(feeId,cashFlowsDate,feeName,oldFeeName,subFundsName,type){
	var actionUrl = PATH_PREFIX + 'updateFeeOrYieldInfoView.do?feeId='+feeId+"&cashFlowsDate="+cashFlowsDate+"&feeName="+feeName+"&oldFeeName="+oldFeeName+"&subFundsName="+subFundsName+"&type="+type;
	window.open(actionUrl);  
}

function deleteFeeOrYieldInfo(feeId,cashFlowsDate,type){
	swal({
		title : "您确定要删除该支付信息?",
		text : "删 除后不可恢复!",
		type : "warning",
		showCancelButton : true,
		confirmButtonColor : "#fc6821",
		confirmButtonText : "是",
		cancelButtonText : "否",
		closeOnConfirm : false,
		closeOnCancel : true
	}, function(isConfirm) {
		if (isConfirm) {
			var actionUrl = PATH_PREFIX + "feeOrYieldInfoDelete.do";
			$.ajax({
				type : 'POST',
				url : actionUrl,
				dataType : 'json',
				data : {
					'feeId' : feeId,
					'cashFlowsDate' : cashFlowsDate,
					'type' : type
				},
				error : function(xhr) {
					sweetAlertAjaxError(xhr);
				},
				success : function(data) {
					if (data=="success") {
						swal("删除成功!", "", "success");
					} else {
						swal("删除失败!", "", "error");
					}
					queryByCondtion(true);
				}
			});
		}
	});
}